package com.opal.jx.service.impl;

import com.opal.jx.entity.table.JxAssessTotal;
import com.opal.jx.entity.table.JxAssessTotalExample;
import com.opal.jx.mapper.mysql.JxAssessPzcjTotalMapper;
import com.opal.jx.service.JxAssessTotalService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("JxAssessPzcjTotalServiceImpl")
public class JxAssessPzcjTotalServiceImpl implements JxAssessTotalService {
    @Autowired
    private JxAssessPzcjTotalMapper jxAssessTotalMapper;
    @Override
    public List<JxAssessTotal> selectJxAssessTotalByCondition(JxAssessTotal condition) {
        JxAssessTotalExample jxAssessTotalExample = this.getJxAssessTotalExample(condition);
        List<JxAssessTotal> jxAssessTotals = jxAssessTotalMapper.selectByExample(jxAssessTotalExample);
        return jxAssessTotals;
    }

    @Override
    public int insertSelective(JxAssessTotal jxAssessTotal) {
        int i = jxAssessTotalMapper.insertSelective(jxAssessTotal);

        return i;
    }

    @Override
    public int deleteByExample(JxAssessTotal condition) {
        return  jxAssessTotalMapper.deleteByExample(this.getJxAssessTotalExample(condition));
    }


    private JxAssessTotalExample getJxAssessTotalExample(JxAssessTotal condition){
        JxAssessTotalExample jxAssessTotalExample = new JxAssessTotalExample();
        JxAssessTotalExample.Criteria criteria = jxAssessTotalExample.createCriteria();
        String empGroup = condition.getEmpGroup();
        Integer assessMonth = condition.getAssessMonth();
        Integer assessYear = condition.getAssessYear();
        Integer assessType = condition.getAssessType();
        if (!StringUtils.isBlank(empGroup)){
            criteria.andEmpGroupEqualTo(empGroup);
        }
        if (assessMonth !=null){
            criteria.andAssessMonthEqualTo(assessMonth);
        }
        if (assessYear !=null){
            criteria.andAssessYearEqualTo(assessYear);
        }
        if (assessType != null){
            criteria.andAssessTypeEqualTo(assessType);
        }
        return jxAssessTotalExample;
    }
}
